package GUI;

import Communications.Login;
import Communications.Register;
import Listeners.RegisterActionListener;

import javax.swing.*;
import javax.swing.text.StyledEditorKit;
import java.awt.*;
import java.io.IOException;

/**
 *
 */
public class RegisterPane extends JPanel{

         JPanel all = new JPanel(new GridLayout(4,0));
         JPanel name,surname,address;
         JLabel lName,lSurname,lAddress;
         static JTextField tName;
        static JTextField tSurname;
        static JTextField tAddress;
         JButton register = new JButton("Register");

     public RegisterPane(){

       setup();

    }
    private void setup(){

        name = new JPanel(new GridLayout(0,2));
        lName = new JLabel("Name");
        tName = new JTextField(15);

        surname = new JPanel(new GridLayout(0,2));
        lSurname = new JLabel("Surname");
        tSurname = new JTextField(15);

        address = new JPanel(new GridLayout(0,2));
        lAddress = new JLabel("Address");
        tAddress = new JTextField(15);


        name.add(lName);
        name.add(tName);

        surname.add(lSurname);
        surname.add(tSurname);

        address.add(lAddress);
        address.add(tAddress);

        register.addActionListener(new RegisterActionListener());

        all.add(name);
        all.add(surname);
        all.add(address);
        all.add(register);

        this.setLocation(0,0);

        this.add(all);
    }
    public static void valuesEntered(){

        if(tName.getText().equals("")||tSurname.getText().equals("")||tAddress.getText().equals("")){
            JOptionPane.showMessageDialog(null,"Name, Surname or Address Field Has Not Been Filled In");
        }
        else{

             try{

               MainFrame.communicate.sendData(tName.getText(),tSurname.getText(),tAddress.getText());
                 System.gc();
            }catch(IOException e){
                e.printStackTrace();
            }

        }

    }
}
